<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>入库查询</title>
		<link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
		<link rel="stylesheet" href="../../../css/public.css" media="all">
	</head>
	<body>
		<div class="layuimini-container">
			<div class="layuimini-main">

				<!--搜索开始-->
				<fieldset class="layui-elem-field layuimini-search">
					<legend>搜索信息</legend>
					<div style="margin: 10px 10px 10px 10px">
						<form class="layui-form layui-form-pane" action="" id="searchFrm">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">查询时间</label>
									<div class="layui-input-inline">
										<input type="text" id="registerTime" name="registerTime" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">申请单编号</label>
									<div class="layui-input-inline">
										<input type="text" name="gatherId" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<a class="layui-btn " lay-submit="" lay-filter="data-search-btn"><label class="layui-icon layui-icon-search"></label>搜索</a>
									<a class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()" lay-filter="data-search-btn"><label
										 class="layui-icon layui-icon-refresh"></label>重置</a>
								</div>
							</div>
						</form>
					</div>
				</fieldset>
				<!--搜索结束-->

				<!--数据列表-->
				<table id="PutRepertory" lay-filter="test"></table>

				<!--入库登记-->
				<div class="layui-row" id="update" style="display:none;">
					<div class="layui-col-md10" align="center">
						<form class="layui-form layui-from-pane" style="margin-top: 20px;" id="accountFomat">

							<table width="880px" style="margin-left: 60px;" height="400px">
								<tr>
									<td colspan="2" width="100%">入库单编号：<span id="productId"></span></td>
								</tr>
								<tr>
									<td width="50%">入库理由：<span id="reason2"></span></td>
									<td width="50%">入库详细理由：<span id="reasonexact"></span></td>
								</tr>
								<tr>
									<td colspan="2" width="100%">
										<table id="PutRepertoryLog" lay-filter="test2"></table>
									</td>
								</tr>
								<tr>
									<td width="50%">应入库总件数：<span id="amountSum"></span></td>
									<td width="50%">本次入库总件数：<span id="gatheredAmountSum"></span></td>
								</tr>
								<tr>
									<td width="50%">应入库总成本：<span id="costPrice"></span></td>
									<td width="50%">本次入库总成本：<span id="costPriceSum"></span></td>
								</tr>
								<tr>
									<td width="50%">复核人：<span id="checker"></span></td>
									<td width="50%">复核时间：<span id="checkTime"></span></td>
								</tr>
							</table>
						</form>
					</div>
				</div>
				
				<!--入库登记-->
				<div class="layui-row" id="look" style="display:none;">
					<div class="layui-col-md10" align="center">
						<form class="layui-form layui-from-pane" style="margin-top: 20px;" id="accountFomat">
							<table width="880px" style="margin-left: 60px;" height="100px" align="center">
								<tr>
									<td width="50%">入库单编号：<span id="gatheredId"></span></td>
									<td width="50%">产品编号：<span id="productId2"></span></td>
								</tr>
								<tr>
									<td width="50%">产品名称：<span id="productName2"></span></td>
									<td width="50%">产品单价：<span id="costPrice2"></span></td>
								</tr>
								<tr>
									<td colspan="2" width="100%">
										<table id="Commoditydetails" lay-filter="test2"></table>
									</td>
								</tr>
							</table>
							<table border="1px" bordercolor="#E6E6E6" width="800px" height="80px" style="margin-bottom: 20px; margin-left: 30px;">
								<tr align="center" bgcolor="#F2F2F2">
									<td>序号</td>
									<td>库房名称</td>
									<td>储存地址编号</td>
									<td>入库时间</td>
									<td>本次入库数量</td>
									<td>本次入库成本</td>
								</tr>
								<tr align="center">
									<td id="pid"></td>
									<td id="storeName"></td>
									<td id="Kind"></td>
									<td id="type"></td>
									<td id="storageUnitShorted"></td>
									<td id="maxCapacityAmount"></td>
								</tr>
							</table>
						</form>
					</div>
				</div>

			</div>
		</div>

		<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
		<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
		<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
		<script src="../../../lib/common/common.js" charset="utf-8"></script>
		<script src="../../../lib/common/selectLayer.js" charset="utf-8"></script>
		<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
		<script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>

		<script type="text/javascript">
			layui.use(['table', 'jquery', 'form', 'laydate'], function() {
				var table = layui.table,
					layer = layui.layer,
					form = layui.form,
					$ = layui.jquery,
					laydate = layui.laydate;

				laydate.render({
					elem: '#registerTime'
				});

				// 监听搜索操作
				form.on('submit(data-search-btn)', function(data) {
					var params = $("#searchFrm").serialize();
					//执行搜索重载
					table.reload('PutRepertory', {
						page: {
							curr: 1
						},
						url: api7 + 'putRepertory/getDispatchByStoreTag?' + params
					});
					return false;
				});

				table.on('row(test2)', function(obj) {
					var data = obj.data;
					console.log(data)
					$("#productId2").html(data.productId)
					$("#productName2").html(data.productName)
					$("#pid").html(data.pid)
					$("#costPrice2").html(data.costPrice)
					$("#storeName").html(data.repertoryCell.storeName)
					$("#storageUnitShorted").html(data.gatheredAmount)
					$("#maxCapacityAmount").html(data.subtotal)
					$("#Kind").html(data.repertoryCell.firstKindId + "-" + data.repertoryCell.secondKindId + "-" + data.repertoryCell.thirdKindId);
					mainIndex = layer.open({
						type: 1,
						title: '查看入库单',
						area: ['980px', '400px'],
						content: $("#look")
					});
					
					$.ajax({
						url: api7 + "PutRepertoryDetails/getAttemperTime",
						method:"get",
						data: {
							pid:data.parentId
						},
						success:function(res) {
							$("#type").html(res.data.attemperTime)
						}
					})
					
				})

				//监听行单击事件
				table.on('row(test)', function(obj) {
					var data = obj.data;
					$("#productId").html(data.gatherId)
					$("#gatheredId").html(data.gatherId)
					if (data.reason == 'R001-1') {
						$("#reason2").html("生产入库")
					} else if (data.reason == 'R001-2') {
						$("#reason2").html("库存初始")
					} else if (data.reason == 'R001-3') {
						$("#reason2").html("赠送")
					} else if (data.reason == 'R001-4') {
						$("#reason2").html("内部归还")
					} else {
						$("#reason2").html("其他归还")
					}

					$("#gatheredAmountSum").html(data.amountSum)
					$("#gatheredId").html(data.gatheredId)

					$("#reasonexact").html(data.reasonexact)
					$("#amountSum").html(data.amountSum)

					$("#subtotal").html(data.subtotal)

					$("#costPrice").html(data.costPriceSum)
					$("#costPriceSum").html(data.costPriceSum)
					$("#checker").html(data.checker)
					$("#checkTime").html(data.checkTime)

					table.render({
						elem: '#PutRepertoryLog',
						url: api7 + "PutRepertoryDetails/getDetailsListByPid?id=" + data.id,
						cols: [
							[{
								field: 'productId',
								title: '产品编号',
								sort: true,
								fixed: 'left',
								align: 'center'
							}, {
								field: 'productName',
								title: '产品名称',
								align: 'center'
							}, {
								field: 'firstKindName',
								title: '存放地址集合',
								templet: '#firstKindName',
								align: 'center'
							}, {
								field: 'storeName',
								title: '库房名称',
								align: 'center',
								templet: '#storeName2'
							}, {
								field: 'amount',
								title: '应入库件数',
								align: 'center',
								templet: "#amount"
							}, {
								field: 'amount',
								title: '已入库件数',
								align: 'center',
								templet:"#amountCell"
							}, {
								field: 'gatheredAmount',
								title: '本次入库数量',
								align: 'center'
							}]
						]
					});

					mainIndex = layer.open({
						type: 1,
						title: '查看入库单',
						area: ['1000px', '650px'],
						content: $("#update")
					});

				});

				//第一个实例
				var tableIns = table.render({
					elem: '#PutRepertory',
					url: api7 + 'putRepertory/getDispatchByStoreTag',
					page: true,
					cols: [
						[{
							field: 'gatherId',
							title: '入库单编号',
							sort: true,
							fixed: 'left',
							align: 'center'
						}, {
							field: 'storer',
							title: '入库人',
							align: 'center'
						}, {
							field: 'reason',
							title: '入库理由',
							templet: '#reason',
							align: 'center'
						}, {
							field: 'registerTime',
							title: '完成时间',
							align: 'center'
						}, {
							field: 'amountSum',
							title: '应入库总件数',
							align: 'center'
						}, {
							field: 'gatheredAmountSum',
							title: '已入库总件数',
							align: 'center'
						}, {
							field: 'costPriceSum',
							title: '入库单状态',
							align: 'center'
						}]
					]
				});
			})
		</script>

		<script type="text/html" id="reason">
			{{# if(d.reason=='R001-1'){d.reason='生产入库'}}
				{{d.reason}}
			{{# }else if(d.reason=='R001-2'){d.reason='库存初始'}}
				{{d.reason}}
			{{# }else if(d.reason=='R001-3'){d.reason='赠送'}}
				{{d.reason}}
			{{# }else if(d.reason=='R001-4'){d.reason='内部归还'}}
				{{d.reason}}
			{{# }else{d.reason='其他归还'}}
				{{d.reason}}
			{{# }}}
		</script>

		<script type="text/html" id="storeName2">
			{{d.repertoryCell.storeName}}
		</script>

		<script type="text/html" id="firstKindName">
			{{d.repertoryCell.firstKindName+"-"+d.repertoryCell.secondKindName+"-"+d.repertoryCell.thirdKindName}}
		</script>
		
		<script type="text/html" id="amountCell">
			{{d.repertoryCell.amount}}
		</script>

	</body>
</html>
